/*
 * author      : 吴中勤
 * date        : 2018/8/22
 * description : 车系转换 sap -> moby
 */

package com.deepexi.adapter.rest.sap.parser;

import com.deepexi.adapter.common.StringUtil;
import com.deepexi.adapter.facade.sap.request.SapPushModelLineBody;
import com.deepexi.adapter.sdk.moby.request.VehicleModelLine;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.List;

public class SapPushModelLineParser extends BaseParser<VehicleModelLine, SapPushModelLineBody> {

    @Override
    protected void convertEachSapItem(SapPushModelLineBody sapItem) {
        if (StringUtil.isNullorEmpty(sapItem.getModelLine())) {
            logger.warn("车系同步, 缺少 车系, {}", sapItem.uglyString());
            return;
        }

        VehicleModelLine mobyItem = new VehicleModelLine();
        mobyItem.setBrandCode(sapItem.getBrandCode());
        mobyItem.setCode(sapItem.getModelLine());
        mobyItem.setName(sapItem.getModelLineText());
        mobyRequestBodyList.add(mobyItem);

    }

    @Override
    protected List<SapPushModelLineBody> parseSapListFromRecordsStr(String recordsStr) {
        Type collectionType = new TypeToken<List<SapPushModelLineBody>>() {
        }.getType();
        return new Gson().fromJson(recordsStr, collectionType);
    }
}
